package com.wxg.mvn;

import java.io.File;
import java.util.Set;

import com.wxg.util.MyUtils;
import com.wxg.util.MyUtils.Prop;

import net.mindview.util.Directory;
import net.mindview.util.Directory.TreeInfo;

public class CleanMavenLastUpdated {

	public static void main(String[] args) {
		CleanMavenLastUpdated cmlu = new CleanMavenLastUpdated();
		
		String propFilePath = MyUtils.userdir() + "/clean.ini";
		Prop prop = MyUtils.readProp(propFilePath);
		
		// Add by wxg 2016年8月21日 删除`specialArtifact`指定的目录
		DeleteSpecialArtifactDirectory dsad = new DeleteSpecialArtifactDirectory();
		dsad.del(prop);
		
		Set<String> keys = prop.keySet();
		for(String key : keys){
			if(key.startsWith("localRepo")){
				String start = prop.get(key);
//				cmlu.test( start );
				cmlu.clean( start );
			}
		}
	}
	
	private void clean(String start){
		System.out.printf( "===[%s]===\n", start);
		TreeInfo ti = Directory.walk(start, ".*lastUpdated$");
		System.out.printf( "文件数: %d\n", ti.files.size());
		String filename = null;
		for(File f : ti.files){
			filename = f.getName();
			if( f.delete() ){
				System.out.printf("删除文件[ %s ]\n", filename);
			}
		}
	}
	
	@SuppressWarnings("unused")
	private void test(String start){
		System.out.printf( "===[%s]===\n", start);
		TreeInfo ti = Directory.walk(start, ".*lastUpdated$");
		System.out.printf( "文件数: %d\n", ti.files.size());
		for(File f : ti.files){
			System.out.println( f.getName() );
		}
	}
	
}
